package com.siwei.mes.entity.experiment.coarseAggregate;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description: 粗骨料-压碎值指标
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class CoarseAggregateYszzb {
    @ApiModelProperty(value = "取样质量")
    private String qyzl = "";
    @ApiModelProperty(value = "平均值")//1
    private String pjz = "";
    @ApiModelProperty(value = "单项结论")//1
    private String dxjl = "";
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "压碎值指标信息")
    private List<CoarseAggregateYszzb.YszzbInfo> yszzbInfo = Collections.singletonList(new CoarseAggregateYszzb.YszzbInfo());

    @Data
    @Accessors(chain = true)
    @ApiModel("压碎值指标信息")
    public static class YszzbInfo {
        @ApiModelProperty(value = "试样质量")
        private String syzl = "";
        @ApiModelProperty(value = "压碎筛余量")
        private String yssyl = "";
        @ApiModelProperty(value = "结果")
        private String jg = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        CoarseAggregateYszzb entity = new CoarseAggregateYszzb();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, CoarseAggregateYszzb.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, CoarseAggregateYszzb.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        CoarseAggregateYszzb entity = JsonUtils.getObject(objJson, CoarseAggregateYszzb.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getPjz()) || "null".equals(entity.getPjz())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        /*if (StringUtils.isBlank(entity.getDxjl()) || "null".equals(entity.getDxjl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        return null;
    }

    public static void setValue(CoarseAggregateYszzb entity, Map<String, Object> data) {
        List<CoarseAggregateYszzb.YszzbInfo> yszzbInfoList = new ArrayList<>();
        YszzbInfo yszzbInfo1 = new YszzbInfo();
        if(data.get("S1") != null){
            yszzbInfo1.setSyzl(data.get("S1").toString());
        }
        if(data.get("S2") != null){
            yszzbInfo1.setYssyl(data.get("S2").toString());
        }
        if(data.get("S3") != null){
            yszzbInfo1.setJg(data.get("S3").toString());
        }
        yszzbInfoList.add(yszzbInfo1);
        YszzbInfo yszzbInfo2 = new YszzbInfo();
        if(data.get("S4") != null){
            yszzbInfo2.setSyzl(data.get("S4").toString());
        }
        if(data.get("S5") != null){
            yszzbInfo2.setYssyl(data.get("S5").toString());
        }
        if(data.get("S6") != null){
            yszzbInfo2.setJg(data.get("S6").toString());
        }
        yszzbInfoList.add(yszzbInfo2);
        YszzbInfo yszzbInfo3 = new YszzbInfo();
        if(data.get("S7") != null){
            yszzbInfo3.setSyzl(data.get("S7").toString());
        }
        if(data.get("S8") != null){
            yszzbInfo3.setYssyl(data.get("S8").toString());
        }
        if(data.get("S9") != null){
            yszzbInfo3.setJg(data.get("S9").toString());
        }
        yszzbInfoList.add(yszzbInfo2);
        entity.setYszzbInfo(yszzbInfoList);
        if(data.get("S10") != null){
            entity.setPjz(data.get("S10").toString());
        }
    }
}
